import axios from "axios";
import Loading from "../../components/loading/index";
// import {METHOD} from "./config";
const axiosInstance = axios.create({
    baseURL:"https://api.it120.cc/small4",
    timeout:10000
})
//请求拦截
var loading = null;
axiosInstance.interceptors.request.use((config)=>{
    loading = Loading.LoadingService();
    // console.log('config',config);

    return config;
},(error)=>{

    return Promise.reject(error);
})
//响应拦截
axiosInstance.interceptors.response.use((response)=>{
    setTimeout(()=>{
        loading.close();
    },2000)
    return response;
},(error)=>{
    setTimeout(()=>{
        loading.close();
    },2000)
    return Promise.reject(error)
})
export function request(method,url,params){
    switch(method){
        case "GET":
           return GET(url,params);

        case "POST":
           return POST(url,params);

        case "UPLOAD":
          return  UPLOAD(url,params);

        case "DOWNLOAD":
          return  DOWNLOAD(url,params);

    }
}
function GET(url,params){
  return  axiosInstance.get(url,params)
}

function POST(url,params){
    return   axiosInstance.post(url,params)
}

function UPLOAD(url,params){
    return  axiosInstance.post(url,params)
}

function DOWNLOAD(url,params){
    return axiosInstance.get(url,params)
}